package com.qipa.netty.client;

import java.io.*;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 * socket客户端发送json
 */
public class SocketSendJson {

    public static void main(String[] args) {
        try {
            Socket s = new Socket("192.168.1.184",8070);

            //构建IO
            InputStream is = s.getInputStream();
            OutputStream os = s.getOutputStream();

            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
            String jsonParams="{\"height\":12,\"weight\":12}";
            //向服务器端发送一条消息
            bw.write(jsonParams+"\n");
            bw.flush();

            //读取服务器返回的消息
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String mess = br.readLine();
            System.out.println("服务器返回："+mess);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
